/*
 * Copyright 2009 David de Mingo
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.shalma;

public class Translation {

	// private DefaultHttpClientConnection connection;

	public void translate(Language language, String text) {

		// text.setTranslation(language, get(language, text));
	}

	// String get(Language language, String text) throws UnknownHostException,
	// IOException, URISyntaxException, ParseException, JSONException,
	// HttpException {
	//
	// String translation = null;
	//
	// HttpParams params = new BasicHttpParams();
	// HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
	// HttpProtocolParams.setContentCharset(params, "UTF-8");
	// HttpProtocolParams.setUserAgent(params, "Shalma");
	// HttpProtocolParams.setUseExpectContinue(params, true);
	//
	// BasicHttpProcessor httpproc = new BasicHttpProcessor();
	// // Required protocol interceptors
	// httpproc.addInterceptor(new RequestContent());
	// httpproc.addInterceptor(new RequestTargetHost());
	// // Recommended protocol interceptors
	// httpproc.addInterceptor(new RequestConnControl());
	// httpproc.addInterceptor(new RequestUserAgent());
	// httpproc.addInterceptor(new RequestExpectContinue());
	//
	// HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
	//
	// HttpContext context = new BasicHttpContext(null);
	// HttpHost host = new HttpHost("ajax.googleapis.com", 80);
	//
	// if (connection == null)
	// connection = new DefaultHttpClientConnection();
	// ConnectionReuseStrategy connStrategy = new
	// DefaultConnectionReuseStrategy();
	//
	// context.setAttribute(ExecutionContext.HTTP_CONNECTION, connection);
	// context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, host);
	//
	// try {
	//
	// if (!connection.isOpen()) {
	// Socket socket = new Socket(host.getHostName(), host.getPort());
	// connection.bind(socket, params);
	// }
	//
	// BasicHttpRequest request = new BasicHttpRequest("GET", uri(
	// language, text));
	//
	// context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
	// request.setParams(params);
	//
	// httpexecutor.preProcess(request, httpproc, context);
	// HttpResponse response = httpexecutor.execute(request, connection,
	// context);
	//
	// response.setParams(params);
	// httpexecutor.postProcess(response, httpproc, context);
	//
	// // System.err.println(">> " + request.getRequestLine().getUri()
	// // + " : " + response.getStatusLine());
	//
	// JSONObject jsonObject = new JSONObject(EntityUtils
	// .toString(response.getEntity()));
	// JSONObject object = jsonObject.getJSONObject("responseData");
	//
	// translation = object.getString("translatedText");
	//
	// if (!connStrategy.keepAlive(response, context))
	// connection.close();
	//
	// } finally {
	// connection.close();
	// }
	//
	// return translation;
	// }
	//
	// String uri(Language language, String text) throws URISyntaxException,
	// UnsupportedEncodingException {
	//
	// StringBuilder sb = new StringBuilder();
	// sb.append("/ajax/services/language/translate?v=1.0&q=");
	// // sb.append(URLEncoder.encode(text.get()));
	// // sb.append("&langpair=");
	// // sb.append(text.getLanguage().getCode());
	// // sb.append("%7C");
	// sb.append(language.getCode());
	// return sb.toString();
	// }
}
